CROSS_COMPILE = #arm-linux-gnueabihf-
CC = $(CROSS_COMPILE)gcc
CXX = $(CROSS_COMPILE)g++

CPPFLAGS = -I./ -DNDEBUG

CFLAGS = -Wall -O3 -std=c99 -g
CXXFLAGS = -Wall -O3 -std=c++11 -g

LDFLAGS = -lpthread -lstdc++

EventLoop_Core = EventLoop.o

EventPool_Core = EventPool.o

OBJS = TestPool.o
TARGETS = TestEventPool

.PHONY: all
all: $(TARGETS)

$(TARGETS): $(OBJS) $(EventPool_Core)
	$(CC) -o $@ $^ $(LDFLAGS)

%.o: %.cpp
	$(CXX) -o $@ -c $< $(CPPFLAGS) $(CXXFLAGS)

%.o: %.c
	$(CC) -o $@ -c $< $(CPPFLAGS) $(CFLAGS)

%.d: %.cpp
	@set -e; rm -f $@; $(CXX) -MM $< $(CPPFLAGS) > $@.$$$$; \
	sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
	rm -f $@.$$$$

%.d: %.c
	@set -e; rm -f $@; $(CC) -MM $< $(CPPFLAGS) > $@.$$$$; \
	sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
	rm -f $@.$$$$

ifneq ($(MAKECMDGOALS), clean)
-include $(OBJS:.o=.d)
-include $(EventLoop_Core:.o=.d)
-include $(EventPool_Core:.o=.d)
endif

.PHONY: clean
clean:
	-rm -rf $(TARGETS) *.d *.o
